package com.richapp.launcher.ui.fragments.home.setting;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.richapp.launcher.R;
import com.richapp.launcher.ui.activities.CreateQRCodeActivity;
import com.richapp.launcher.ui.view.TabPageView;
import com.richapp.launcher.utils.Tools;

public class SettingFragment extends Fragment {
	private TabPageView mTabPageView;
    private ImageView setting_monitor,settiing_network,setting_phone_control;
	private Intent intent = null;
	private static final String TAG = SettingFragment.class.getName();
	
    @Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.smart_setting,container,false);
		intent = new Intent(getActivity(), CreateQRCodeActivity.class);
		init(view);
		return view;
	}
	
	private void init(View view){
		settiing_network = (ImageView)view.findViewById(R.id.settiing_network);
		setting_monitor = (ImageView)view.findViewById(R.id.setting_monitor);
		setting_phone_control = (ImageView)view.findViewById(R.id.setting_phone_control);
		
		//setting_monitor.setOnKeyListener(onKeyListener);
		setting_phone_control.setOnKeyListener(onKeyListener);
		
		setting_phone_control.setOnClickListener(click);
		
		setting_monitor.setOnClickListener(click);
		settiing_network.setOnClickListener(click);
	}
	
	@Override
	public void onAttach(Activity activity) {
		mTabPageView = (TabPageView) activity.findViewById(R.id.tabPageView);
		super.onAttach(activity);
	}
	
	OnClickListener click = new OnClickListener() {
		@Override
		public void onClick(View v) {
            switch (v.getId()) {
			case R.id.setting_phone_control:
				getActivity().startActivity(intent);
				break;
			case R.id.setting_monitor:
				String msg = "还没有开放哦!";
				Toast toast = Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();

/*				StringBuffer buffer = new StringBuffer();
				buffer.append("品牌:").append(Build.BRAND).append("\n");
				buffer.append("Product:").append(Build.PRODUCT).append("\n");
				buffer.append("CPU_ABI:").append(Build.CPU_ABI).append("\n");
				buffer.append("TAGS:").append(Build.TAGS).append("\n");
				buffer.append("VERSION_CODES.BASE:").append(Build.VERSION_CODES.BASE).append("\n");
				buffer.append("MODEL:").append(Build.MODEL).append("\n");
				buffer.append("SDK:").append(Build.VERSION.SDK).append("\n");
				buffer.append("VERSION.RELEASE:").append(Build.VERSION.RELEASE).append("\n");
				buffer.append("DEVICE:").append(Build.DEVICE).append("\n");
				buffer.append("DISPLAY:").append(Build.DISPLAY).append("\n");
				buffer.append("BOARD:").append(Build.BOARD).append("\n");
				buffer.append("FINGERPRINT:").append(Build.FINGERPRINT).append("\n");
				buffer.append("ID:").append(Build.ID).append("\n");
				buffer.append("MANUFACTURER:").append(Build.MANUFACTURER).append("\n");
				buffer.append("USER:").append(Build.USER).append("\n");
				Toast toast = Toast.makeText(getActivity(), buffer.toString(), Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();*/
				break;
			case R.id.settiing_network:
				Tools.openApp(getActivity(),"com.vst.wifianalyze");
				break;
			default:
				break;
			}			
		}
	};
	
	OnKeyListener onKeyListener = new OnKeyListener() {
		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event) {
			boolean clickView=(v==setting_monitor||v==setting_phone_control);
			if (clickView&&(event.getAction() == KeyEvent.ACTION_DOWN)&&(keyCode == KeyEvent.KEYCODE_DPAD_UP)) {
				if (mTabPageView != null && mTabPageView.getCurrTabView() != null) {
					  mTabPageView.getCurrTabView().requestFocus();
	            }
			}
			return false;
		}
	};

	public static SettingFragment getInstance() {
		return new SettingFragment();
	}
}
